<template>
	<view class="content">
		<view class="header">
			<image src="../../static/shilu-login/logo.png"></image>
		</view>

		<view class="list">
			<view class="list-call">
				<image class="img" src="../../static/shilu-login/1.png"></image>
				<input class="sl-input" v-model="phone" type="number" maxlength="11" placeholder="输入手机号" />
			</view>
			<view class="list-call">
				<image class="img" src="../../static/shilu-login/2.png"></image>
				<input class="sl-input" v-model="password" type="text" maxlength="32" placeholder="输入密码"
					password="true" />
			</view>

			<view class="button-login" hover-class="button-hover" @click="bindLogin()">
				<text>登录</text>
			</view>
		</view>

		<view class="agreement">
			<navigator url="forget" open-type="navigate">忘记密码</navigator>
			<navigator url="reg" open-type="navigate">注册账户</navigator>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				phone: '',
				password: ''
			};
		},
		methods: {
			bindLogin() {
				if (this.phone.length !== 11) {
					uni.showToast({
						icon: 'none',
						title: '手机号不正确'
					});
					return;
				}

				if (this.password.length < 3) {
					uni.showToast({
						icon: 'none',
						title: '密码不正确'
					});
					return;
				}

				uni.request({
					// url: 'http://****/login.html',
					url: 'http://47.102.217.172:8088/MobieShop5-1/member/login',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						uname: this.phone,
						password: this.password
					},
					method: 'POST',
					dataType: 'json',
					success: (res) => {
						console.log(res);
						if (res.data.status !== 0) {
							console.log("login error!");
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
						} else {
							// 成功后的逻辑
							console.log("login success!");
							// uni.navigateBack();
							uni.navigateTo({
								url: '../index/index'
							});
						}
					}
				});
			}
		}
	};
</script>